iT邦幫忙

2024 iThome 鐵人賽

DAY 14
0

npx expo start 是用來啟動 Expo server。
terminal 提示 Expo 版本需要更新。

$ npx expo start
Starting project at D:\Jim\NotificationProgress
Starting Metro Bundler
The following packages should be updated for best compatibility with the installed expo version:
  expo@51.0.32 - expected version: ~51.0.34
Your project may not work correctly until you install the expected versions of the packages.
Waiting on http://localhost:8081
Logs for your project will appear below.

使用 npm install expo@~51.0.34 更新版本。

接著用 npx expo run:android 建構 Android 專案。

$ npx expo run:android
› Building app...
Starting a Gradle Daemon (subsequent builds will be faster)
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at 'D:\Jim\NotificationProgress\android\local.properties'.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 38s
10 actionable tasks: 2 executed, 8 up-to-date
Error: D:\Jim\NotificationProgress\android\gradlew.bat app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a,armeabi-v7a exited with non-zero code: 1
Error: D:\Jim\NotificationProgress\android\gradlew.bat app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a,armeabi-v7a exited with non-zero code: 1
    at ChildProcess.completionListener (D:\Jim\NotificationProgress\node_modules\@expo\spawn-async\build\spawnAsync.js:42:23)
    at Object.onceWrapper (node:events:634:26)
    at ChildProcess.emit (node:events:519:28)
    at cp.emit (D:\Jim\NotificationProgress\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
    ...
    at spawnAsync (D:\Jim\NotificationProgress\node_modules\@expo\spawn-async\build\spawnAsync.js:7:23)
    at spawnGradleAsync (D:\Jim\NotificationProgress\node_modules\@expo\cli\build\src\start\platforms\android\gradle.js:96:48)
    at assembleAsync (D:\Jim\NotificationProgress\node_modules\@expo\cli\build\src\start\platforms\android\gradle.js:74:18)
    at runAndroidAsync (D:\Jim\NotificationProgress\node_modules\@expo\cli\build\src\run\android\runAndroidAsync.js:45:37)

錯誤訊息顯示,在 android 目錄下的 local.properties 尚未使用 ANDROID_HOME 變數來指定 SDK 路徑。

回到專案資料夾,在 android 目錄下建立 local.properties 檔案。並添加下列 SDK 路徑。

sdk.dir=C\:\\Users\\User\\AppData\\Local\\Android\\Sdk

接著遇到 NDK 路徑未指定錯誤。

> Configure project :expo-modules-core
Warning: Failed to download any source lists!
Warning: Still waiting for package manifests to be fetched remotely.

FAILURE: Build failed with an exception.

* Where:
Script 'D:\Jim\NotificationProgress\node_modules\expo-modules-autolinking\scripts\android\autolinking_implementation.gradle' line: 408

* What went wrong:
A problem occurred evaluating project ':expo'.
> A problem occurred configuring project ':expo-modules-core'.
   > NDK not configured. Download it with SDK manager. Preferred NDK version is '25.1.8937393'.

使用 IntelliJ IDEA 安裝對應版本的 NDK 後
https://ithelp.ithome.com.tw/upload/images/20240925/20151956P1eUCXDdLm.png

在 local.properties 檔案 添加以下路徑。

ndk.dir=C\:\\Users\\User\\AppData\\Local\\Android\\Sdk\\ndk\\25.1.8937393

上一篇
[Day 13] React Expo Notification 範例解說
下一篇
[Day 15] React Expo push token 無法取得問題
系列文
跨平台協同:在 React Native 和 Kotlin 應用中實現無縫交互 -以 Notification 為例30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言